﻿

namespace WooEngine.Utility.Security.Base
{

	[System.Serializable]
	public class EncryptInt
	{
		public static System.Random random = new System.Random();

		private int INT_SECRET_KEY = 1;

		private int _value = 1;
		public int Value
		{
			set { _value = value ^ INT_SECRET_KEY; }
			get { return _value ^ INT_SECRET_KEY; }
		}

		public EncryptInt()
		{
			INT_SECRET_KEY = random.Next(0, 255);// Convert.ToInt32((Time.time * 1000));
		}

		public static EncryptInt Get(int v)
		{
			EncryptInt ei = v;
			return ei;
		}

		public static implicit operator EncryptInt(int value)
		{
			EncryptInt encryptInt = new EncryptInt();
			encryptInt.Value = value;

			return encryptInt;
		}

		public static implicit operator int(EncryptInt encryptInt)
		{
			return encryptInt.Value;
		}

		public static bool operator ==(EncryptInt _a, EncryptInt _b)
		{
			return _a.Value == _b.Value;
		}

		public static bool operator !=(EncryptInt _a, EncryptInt _b)
		{
			return _a.Value != _b.Value;
		}

	  public override bool Equals (object obj)
	  {
	    return Value.Equals ((obj as EncryptInt).Value);
	  }
	  
	  public override int GetHashCode ()
	  {
	    return Value.GetHashCode ();
	  }

		public string ToString(string format)
		{
			return Value.ToString(format);
		}

		public override string ToString()
		{
			return Value.ToString();
		}
	}

}